#include <stdio.h>
#include <memory.h>
#include <conio.h>
#include <time.h>



#define row 14
#define column 35

int main()
{
	FILE *outfile, *outfile2;    //output file 
	int i,j,ii,jj,k,l,s,t;
	int num = 0;

	int g [row*column] ;
	int start_row, start_column, end_row,end_column;
	time_t Start, End;
	double TimeUsed;

	outfile = fopen("h_out.bin", "wb" );
	outfile2 = fopen("h_out.ndx", "w");
	

	time ( &Start );
	s = 1;  // column
	t = 2;  //row
	for(i = t; i<=row; i=i+t)
		for (j = s; j<=column; j=j+s)
			for ( ii = 1; ii<= row-i+1; ii++)
				for (jj=1; jj<=column-j+1;jj++){
                    memset(g, 0 , sizeof(g));
					// this block is used to generate h(t)
					for(k=ii;k<=(ii+(i-1)/t);k++)
						for (l=jj;l<=(jj+j-1);l++)
							//g[(k-1)*column+l-1] = 1;
					      g[(l-1)*row+k-1] = 1;
					for(k=ii+(i-1)/t+1;k<=ii+i-1;k++)
						for (l=jj;l<=(jj+j-1);l++)
							//g[(k-1)*column+l-1] = -1;
							g[(l-1)*row+k-1] = -1;
					
					/*start_row = ii;
					start_column = jj;
					end_row = ii+(i-1)/t;
					end_column = jj+j-1;
					if (start_row != end_row && start_column != end_column){
						g[(start_column-1)*row+start_row-1] += 1;
						g[(end_column-1)*row+end_row-1] += 1;
						g[(start_column-1)*row+end_row-1] -= 1;
						g[(end_column-1)*row+start_row-1] -= 1;
					}else if (start_row == end_row && start_column == end_column){
                        g[(end_column-1)*row+end_row-1] += 1;
						if ( start_row-1 >= 1 ){
							g[(end_column-1)*row+(start_row-2)] -= 1;
						}
						if ( start_column-1 >= 1 ){
							g[(start_column-2)*row+(start_row-1)] -= 1;
						}
						if (start_row-1 >= 1  &&  start_column-1 >= 1){
							g[(start_column-2)*row+(start_row-2)] += 1;
						}
					}else if (start_row == end_row){
						g[(end_column-1)*row+end_row-1] += 1;
						g[(start_column-1)*row+start_row-1] -= 1;
						if (start_row-1 >= 1){
							g[(end_column-1)*row+(start_row-2)] -= 1;
							g[(start_column-1)*row+(start_row-2)] += 1;
						}						
					}else if (start_column == end_column){
						g[(end_column-1)*row+end_row-1] += 1;
						g[(start_column-1)*row+start_row-1] -= 1;

					}
					start_row = ii+(i-1)/t+1;
					start_column = jj;
					end_row = ii+(i-1);
					end_column = jj+j-1;
					if (start_row != end_row && start_column != end_column){
						g[(start_column-1)*row+start_row-1] -= 1;
						g[(end_column-1)*row+end_row-1] -= 1;
						g[(start_column-1)*row+end_row-1] += 1;
						g[(end_column-1)*row+start_row-1] += 1;
					}else if (start_row == end_row && start_column == end_column){
                        g[(end_column-1)*row+end_row-1] -= 1;
						if ( start_row-1 >= 1 ){
							g[(end_column-1)*row+(start_row-2)] += 1;
						}
						if ( start_column-1 >= 1 ){
							g[(start_column-2)*row+(start_row-1)] += 1;
						}
						if (start_row-1 >= 1  &&  start_column-1 >= 1){
							g[(start_column-2)*row+(start_row-2)] -= 1;
						}
					}else if (start_row == end_row){
						g[(end_column-1)*row+end_row-1] -= 1;
						g[(start_column-1)*row+start_row-1] += 1;
						if (start_row-1 >= 1){
							g[(end_column-1)*row+(start_row-2)] += 1;
							g[(start_column-1)*row+(start_row-2)] -= 1;
						}						
					}else if (start_column == end_column){
						g[(end_column-1)*row+end_row-1] -= 1;
						g[(start_column-1)*row+start_row-1] += 1;

					}*/

					fwrite(g,sizeof(int),row*column,outfile);
				
					fprintf(outfile2,"%d,1,%d,%d,%d,%d\n",num,ii,jj,ii+i-1,jj+j-1);
					num++;
				}
	

	/*------------------------------------------------------------------
	
	------------------------------------------------------------------*/
	s = 2;
    t = 1;
	for(i = t; i<=row; i=i+t)
		for (j = s; j<=column; j=j+s)
			for ( ii = 1; ii<= row-i+1; ii++)
				for (jj=1; jj<=column-j+1;jj++){
                    memset(g, 0 , sizeof(g));
					/* this block is used to generate h(t)----*/
					for(k=ii;k<=(ii+(i-1));k++)
						for (l=jj;l<=(jj+(j-1)/s);l++)
							//g[(k-1)*column+l-1] = 1;
					        g[(l-1)*row+k-1] = 1;
					for(k=ii;k<=ii+i-1;k++)
						for (l=jj+(j-1)/s+1;l<=(jj+j-1);l++)
							//g[(k-1)*column+l-1] = -1;
					        g[(l-1)*row+k-1] = -1;
					
				
					/*start_row = ii;
					start_column = jj;
					end_row = ii+(i-1);
					end_column = jj+(j-1)/s;
					if (start_row != end_row && start_column != end_column){
						g[(start_column-1)*row+start_row-1] += 1;
						g[(end_column-1)*row+end_row-1] += 1;
						g[(start_column-1)*row+end_row-1] -= 1;
						g[(end_column-1)*row+start_row-1] -= 1;
					}else if (start_row == end_row && start_column == end_column){
                        g[(end_column-1)*row+end_row-1] += 1;
						if ( start_row-1 >= 1 ){
							g[(end_column-1)*row+(start_row-2)] -= 1;
						}
						if ( start_column-1 >= 1 ){
							g[(start_column-2)*row+(start_row-1)] -= 1;
						}
						if (start_row-1 >= 1  &&  start_column-1 >= 1){
							g[(start_column-2)*row+(start_row-2)] += 1;
						}
					}else if (start_row == end_row){
						g[(end_column-1)*row+end_row-1] += 1;
						g[(start_column-1)*row+start_row-1] -= 1;
						if (start_row-1 >= 1){
							g[(end_column-1)*row+(start_row-2)] -= 1;
							g[(start_column-1)*row+(start_row-2)] += 1;
						}						
					}else if (start_column == end_column){
						g[(end_column-1)*row+end_row-1] += 1;
						g[(start_column-1)*row+start_row-1] -= 1;

					}
					start_row = ii;
					start_column = jj+(j-1)/s+1;
					end_row = ii+(i-1);
					end_column = jj+(j-1);
					if (start_row != end_row && start_column != end_column){
						g[(start_column-1)*row+start_row-1] -= 1;
						g[(end_column-1)*row+end_row-1] -= 1;
						g[(start_column-1)*row+end_row-1] += 1;
						g[(end_column-1)*row+start_row-1] += 1;
					}else if (start_row == end_row && start_column == end_column){
                        g[(end_column-1)*row+end_row-1] -= 1;
						if ( start_row-1 >= 1 ){
							g[(end_column-1)*row+(start_row-2)] += 1;
						}
						if ( start_column-1 >= 1 ){
							g[(start_column-2)*row+(start_row-1)] += 1;
						}
						if (start_row-1 >= 1  &&  start_column-1 >= 1){
							g[(start_column-2)*row+(start_row-2)] -= 1;
						}
					}else if (start_row == end_row){
						g[(end_column-1)*row+end_row-1] -= 1;
						g[(start_column-1)*row+start_row-1] += 1;
						if (start_row-1 >= 1){
							g[(end_column-1)*row+(start_row-2)] += 1;
							g[(start_column-1)*row+(start_row-2)] -= 1;
						}						
					}else if (start_column == end_column){
						g[(end_column-1)*row+end_row-1] -= 1;
						g[(start_column-1)*row+start_row-1] += 1;

					}*/

					fwrite(g,sizeof(int),row*column,outfile);
					fprintf(outfile2,"%d,2,%d,%d,%d,%d\n",num,ii,jj,ii+i-1,jj+j-1);
					num++;
				}
	/*------------------------------------------------------------------
	
	------------------------------------------------------------------*/
	s = 1;
	t = 3;
	for(i = t; i<=row; i=i+t)
			for (j = s; j<=column; j=j+s)
				for ( ii = 1; ii<= row-i+1; ii++)
					for (jj=1; jj<=column-j+1;jj++){
						memset(g, 0 , sizeof(g));
						//*------This block is used to generate h(t)
						for(k=ii;k<=(ii+(i-1)/t);k++)
							for (l=jj;l<=(jj+j-1);l++)
								//g[(k-1)*column+l-1] = 1;
						        g[(l-1)*row+k-1] = 1;
						for(k=ii+(i-1)/t+1;k<=ii+(i-1)*2/t;k++)
							for (l=jj;l<=(jj+j-1);l++)
								//g[(k-1)*column+l-1] = -1;
						        g[(l-1)*row+k-1] = -1;
						for(k=ii+(i-1)*2/t+1;k<=ii+(i-1);k++)
							for (l=jj;l<=(jj+j-1);l++)
								//g[(k-1)*column+l-1] = 1;
						        g[(l-1)*row+k-1] = 1;
						
						/*start_row = ii;
						start_column = jj;
						end_row = ii+(i-1)/t;
						end_column = jj+(j-1);
						if (start_row != end_row && start_column != end_column){
							g[(start_column-1)*row+start_row-1] += 1;
							g[(end_column-1)*row+end_row-1] += 1;
							g[(start_column-1)*row+end_row-1] -= 1;
							g[(end_column-1)*row+start_row-1] -= 1;
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] += 1;
							if ( start_row-1 >= 1 ){
								g[(end_column-1)*row+(start_row-2)] -= 1;
							}
							if ( start_column-1 >= 1 ){
								g[(start_column-2)*row+(start_row-1)] -= 1;
							}
							if (start_row-1 >= 1  &&  start_column-1 >= 1){
								g[(start_column-2)*row+(start_row-2)] += 1;
							}
						}else if (start_row == end_row){
							g[(end_column-1)*row+end_row-1] += 1;
							g[(start_column-1)*row+start_row-1] -= 1;
							if (start_row-1 >= 1){
								g[(end_column-1)*row+(start_row-2)] -= 1;
								g[(start_column-1)*row+(start_row-2)] += 1;
							}						
						}else if (start_column == end_column){
							g[(end_column-1)*row+end_row-1] += 1;
							g[(start_column-1)*row+start_row-1] -= 1;

						}
						start_row = ii+(i-1)/t+1;
						start_column = jj;
						end_row = ii+(i-1)*2/t;
						end_column = jj+(j-1);
						if (start_row != end_row && start_column != end_column){
							g[(start_column-1)*row+start_row-1] -= 1;
							g[(end_column-1)*row+end_row-1] -= 1;
							g[(start_column-1)*row+end_row-1] += 1;
							g[(end_column-1)*row+start_row-1] += 1;
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] -= 1;
							if ( start_row-1 >= 1 ){
								g[(end_column-1)*row+(start_row-2)] += 1;
							}
							if ( start_column-1 >= 1 ){
								g[(start_column-2)*row+(start_row-1)] += 1;
							}
							if (start_row-1 >= 1  &&  start_column-1 >= 1){
								g[(start_column-2)*row+(start_row-2)] -= 1;
							}
						}else if (start_row == end_row){
							g[(end_column-1)*row+end_row-1] -= 1;
							g[(start_column-1)*row+start_row-1] += 1;
							if (start_row-1 >= 1){
								g[(end_column-1)*row+(start_row-2)] += 1;
								g[(start_column-1)*row+(start_row-2)] -= 1;
							}						
						}else if (start_column == end_column){
							g[(end_column-1)*row+end_row-1] -= 1;
							g[(start_column-1)*row+start_row-1] += 1;

						}
						start_row = ii+(i-1)*2/t+1;
						start_column = jj;
						end_row = ii+(i-1);
						end_column = jj+(j-1);
						if (start_row != end_row && start_column != end_column){
							g[(start_column-1)*row+start_row-1] += 1;
							g[(end_column-1)*row+end_row-1] += 1;
							g[(start_column-1)*row+end_row-1] -= 1;
							g[(end_column-1)*row+start_row-1] -= 1;
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] += 1;
							if ( start_row-1 >= 1 ){
								g[(end_column-1)*row+(start_row-2)] -= 1;
							}
							if ( start_column-1 >= 1 ){
								g[(start_column-2)*row+(start_row-1)] -= 1;
							}
							if (start_row-1 >= 1  &&  start_column-1 >= 1){
								g[(start_column-2)*row+(start_row-2)] += 1;
							}
						}else if (start_row == end_row){
							g[(end_column-1)*row+end_row-1] += 1;
							g[(start_column-1)*row+start_row-1] -= 1;
							if (start_row-1 >= 1){
								g[(end_column-1)*row+(start_row-2)] -= 1;
								g[(start_column-1)*row+(start_row-2)] += 1;
							}						
						}else if (start_column == end_column){
							g[(end_column-1)*row+end_row-1] += 1;
							g[(start_column-1)*row+start_row-1] -= 1;

						}*/


						fwrite(g,sizeof(int),row*column,outfile);
						fprintf(outfile2,"%d,3,%d,%d,%d,%d\n",num,ii,jj,ii+i-1,jj+j-1);
						num++;
					}
	/*------------------------------------------------------------------
	
	------------------------------------------------------------------*/
	s = 3;
	t = 1;
	for(i = t; i<=row; i=i+t)
			for (j = s; j<=column; j=j+s)
				for ( ii = 1; ii<= row-i+1; ii++)
					for (jj=1; jj<=column-j+1;jj++){
						memset(g, 0 , sizeof(g));
						//*----this block is used to generate h(t)
						for(k=ii;k<=ii+(i-1);k++)
							for (l=jj;l<=jj+(j-1)/s;l++)
								//g[(k-1)*column+l-1] = 1;
						        g[(l-1)*row+k-1] = 1;
						for(k=ii; k<=ii+(i-1);k++)
							for (l=jj+(j-1)/s+1;l<=jj+(j-1)*2/s;l++)
								//g[(k-1)*column+l-1] = -1;
								g[(l-1)*row+k-1] = -1;
						for(k=ii; k<=ii+(i-1);k++)
							for (l=jj+(j-1)*2/s+1;l<=(jj+j-1);l++)
								//g[(k-1)*column+l-1] = 1;
								g[(l-1)*row+k-1] = 1;
						
						/*start_row = ii;
						start_column = jj;
						end_row = ii+(i-1);
						end_column = jj+(j-1)/s;
						if (start_row != end_row && start_column != end_column){
							g[(start_column-1)*row+start_row-1] += 1;
							g[(end_column-1)*row+end_row-1] += 1;
							g[(start_column-1)*row+end_row-1] -= 1;
							g[(end_column-1)*row+start_row-1] -= 1;
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] += 1;
							if ( start_row-1 >= 1 ){
								g[(end_column-1)*row+(start_row-2)] -= 1;
							}
							if ( start_column-1 >= 1 ){
								g[(start_column-2)*row+(start_row-1)] -= 1;
							}
							if (start_row-1 >= 1  &&  start_column-1 >= 1){
								g[(start_column-2)*row+(start_row-2)] += 1;
							}
						}else if (start_row == end_row){
							g[(end_column-1)*row+end_row-1] += 1;
							g[(start_column-1)*row+start_row-1] -= 1;
							if (start_row-1 >= 1){
								g[(end_column-1)*row+(start_row-2)] -= 1;
								g[(start_column-1)*row+(start_row-2)] += 1;
							}						
						}else if (start_column == end_column){
							g[(end_column-1)*row+end_row-1] += 1;
							g[(start_column-1)*row+start_row-1] -= 1;

						}
						start_row = ii;
						start_column = jj+(j-1)/s+1;
						end_row = ii+(i-1);
						end_column = jj+(j-1)*2/s;
						if (start_row != end_row && start_column != end_column){
							g[(start_column-1)*row+start_row-1] -= 1;
							g[(end_column-1)*row+end_row-1] -= 1;
							g[(start_column-1)*row+end_row-1] += 1;
							g[(end_column-1)*row+start_row-1] += 1;
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] -= 1;
							if ( start_row-1 >= 1 ){
								g[(end_column-1)*row+(start_row-2)] += 1;
							}
							if ( start_column-1 >= 1 ){
								g[(start_column-2)*row+(start_row-1)] += 1;
							}
							if (start_row-1 >= 1  &&  start_column-1 >= 1){
								g[(start_column-2)*row+(start_row-2)] -= 1;
							}
						}else if (start_row == end_row){
							g[(end_column-1)*row+end_row-1] -= 1;
							g[(start_column-1)*row+start_row-1] += 1;
							if (start_row-1 >= 1){
								g[(end_column-1)*row+(start_row-2)] += 1;
								g[(start_column-1)*row+(start_row-2)] -= 1;
							}						
						}else if (start_column == end_column){
							g[(end_column-1)*row+end_row-1] -= 1;
							g[(start_column-1)*row+start_row-1] += 1;

						}
						start_row = ii;
						start_column = jj+(j-1)*2/s+1;
						end_row = ii+(i-1);
						end_column = jj+(j-1);
						if (start_row != end_row && start_column != end_column){
							g[(start_column-1)*row+start_row-1] += 1;
							g[(end_column-1)*row+end_row-1] += 1;
							g[(start_column-1)*row+end_row-1] -= 1;
							g[(end_column-1)*row+start_row-1] -= 1;
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] += 1;
							if ( start_row-1 >= 1 ){
								g[(end_column-1)*row+(start_row-2)] -= 1;
							}
							if ( start_column-1 >= 1 ){
								g[(start_column-2)*row+(start_row-1)] -= 1;
							}
							if (start_row-1 >= 1  &&  start_column-1 >= 1){
								g[(start_column-2)*row+(start_row-2)] += 1;
							}
						}else if (start_row == end_row){
							g[(end_column-1)*row+end_row-1] += 1;
							g[(start_column-1)*row+start_row-1] -= 1;
							if (start_row-1 >= 1){
								g[(end_column-1)*row+(start_row-2)] -= 1;
								g[(start_column-1)*row+(start_row-2)] += 1;
							}						
						}else if (start_column == end_column){
							g[(end_column-1)*row+end_row-1] += 1;
							g[(start_column-1)*row+start_row-1] -= 1;

						}*/

						fwrite(g,sizeof(int),row*column,outfile);
						fprintf(outfile2,"%d,4,%d,%d,%d,%d\n",num,ii,jj,ii+i-1,jj+j-1);
						num++;
					}
	/*------------------------------------------------------------------
	
	------------------------------------------------------------------*/
	s = 2;
	t = 2;
	for(i = t; i<=row; i=i+t)
				for (j = s; j<=column; j=j+s)
					for ( ii = 1; ii<= row-i+1; ii++)
						for (jj=1; jj<=column-j+1;jj++){
							memset(g, 0 , sizeof(g));
							// This block is used to generate h(t)------------------
							for(k=ii;k<=ii+(i-1)/t;k++)
								for (l=jj;l<=jj+(j-1)/s;l++)
									//g[(k-1)*column+l-1] = 1;
									g[(l-1)*row+k-1] = 1;
							for(k=ii; k<=ii+(i-1)/t;k++)
								for (l=jj+(j-1)/s+1;l<=jj+(j-1);l++)
									//g[(k-1)*column+l-1] = -1;
									g[(l-1)*row+k-1] = - 1;
							for(k=ii+(i-1)/t+1; k<=ii+(i-1);k++)
								for (l=jj;l<=jj+(j-1)/s;l++)
									//g[(k-1)*column+l-1] = -1;
									g[(l-1)*row+k-1] = -1;
							for(k=ii+(i-1)/t+1; k<=ii+(i-1);k++)
								for (l=jj+(j-1)/s+1;l<=(jj+j-1);l++)
									//g[(k-1)*column+l-1] = 1;
									g[(l-1)*row+k-1] = 1;
							//--------------------------------------------------------
							/*start_row = ii;
							start_column = jj;
							end_row = ii+(i-1)/t;
							end_column = jj+(j-1)/s;
							if (start_row != end_row && start_column != end_column){
								g[(start_column-1)*row+start_row-1] += 1;
								g[(end_column-1)*row+end_row-1] += 1;
								g[(start_column-1)*row+end_row-1] -= 1;
								g[(end_column-1)*row+start_row-1] -= 1;
							}else if (start_row == end_row && start_column == end_column){
								g[(end_column-1)*row+end_row-1] += 1;
								if ( start_row-1 >= 1 ){
									g[(end_column-1)*row+(start_row-2)] -= 1;
								}
								if ( start_column-1 >= 1 ){
									g[(start_column-2)*row+(start_row-1)] -= 1;
								}
								if (start_row-1 >= 1  &&  start_column-1 >= 1){
									g[(start_column-2)*row+(start_row-2)] += 1;
								}
							}else if (start_row == end_row){
								g[(end_column-1)*row+end_row-1] += 1;
								g[(start_column-1)*row+start_row-1] -= 1;
								if (start_row-1 >= 1){
									g[(end_column-1)*row+(start_row-2)] -= 1;
									g[(start_column-1)*row+(start_row-2)] += 1;
								}						
							}else if (start_column == end_column){
								g[(end_column-1)*row+end_row-1] += 1;
								g[(start_column-1)*row+start_row-1] -= 1;

							}
							start_row = ii;
							start_column = jj+(j-1)/s+1;
							end_row = ii+(i-1)/t;
							end_column = jj+(j-1);
							if (start_row != end_row && start_column != end_column){
								g[(start_column-1)*row+start_row-1] -= 1;
								g[(end_column-1)*row+end_row-1] -= 1;
								g[(start_column-1)*row+end_row-1] += 1;
								g[(end_column-1)*row+start_row-1] += 1;
							}else if (start_row == end_row && start_column == end_column){
								g[(end_column-1)*row+end_row-1] -= 1;
								if ( start_row-1 >= 1 ){
									g[(end_column-1)*row+(start_row-2)] += 1;
								}
								if ( start_column-1 >= 1 ){
									g[(start_column-2)*row+(start_row-1)] += 1;
								}
								if (start_row-1 >= 1  &&  start_column-1 >= 1){
									g[(start_column-2)*row+(start_row-2)] -= 1;
								}
							}else if (start_row == end_row){
								g[(end_column-1)*row+end_row-1] -= 1;
								g[(start_column-1)*row+start_row-1] += 1;
								if (start_row-1 >= 1){
									g[(end_column-1)*row+(start_row-2)] += 1;
									g[(start_column-1)*row+(start_row-2)] -= 1;
								}						
							}else if (start_column == end_column){
								g[(end_column-1)*row+end_row-1] -= 1;
								g[(start_column-1)*row+start_row-1] += 1;

							}
							start_row = ii+(i-1)/t+1;
							start_column = jj+(j-1)/s+1;
							end_row = ii+(i-1);
							end_column = jj+(j-1);
							if (start_row != end_row && start_column != end_column){
								g[(start_column-1)*row+start_row-1] += 1;
								g[(end_column-1)*row+end_row-1] += 1;
								g[(start_column-1)*row+end_row-1] -= 1;
								g[(end_column-1)*row+start_row-1] -= 1;
							}else if (start_row == end_row && start_column == end_column){
								g[(end_column-1)*row+end_row-1] += 1;
								if ( start_row-1 >= 1 ){
									g[(end_column-1)*row+(start_row-2)] -= 1;
								}
								if ( start_column-1 >= 1 ){
									g[(start_column-2)*row+(start_row-1)] -= 1;
								}
								if (start_row-1 >= 1  &&  start_column-1 >= 1){
									g[(start_column-2)*row+(start_row-2)] += 1;
								}
							}else if (start_row == end_row){
								g[(end_column-1)*row+end_row-1] += 1;
								g[(start_column-1)*row+start_row-1] -= 1;
								if (start_row-1 >= 1){
									g[(end_column-1)*row+(start_row-2)] -= 1;
									g[(start_column-1)*row+(start_row-2)] += 1;
								}						
							}else if (start_column == end_column){
								g[(end_column-1)*row+end_row-1] += 1;
								g[(start_column-1)*row+start_row-1] -= 1;

							}
							start_row = ii+(i-1)/t+1;
							start_column = jj;
							end_row = ii+(i-1);
							end_column = jj+(j-1)/s;
							if (start_row != end_row && start_column != end_column){
								g[(start_column-1)*row+start_row-1] -= 1;
								g[(end_column-1)*row+end_row-1] -= 1;
								g[(start_column-1)*row+end_row-1] += 1;
								g[(end_column-1)*row+start_row-1] += 1;
							}else if (start_row == end_row && start_column == end_column){
								g[(end_column-1)*row+end_row-1] -= 1;
								if ( start_row-1 >= 1 ){
									g[(end_column-1)*row+(start_row-2)] += 1;
								}
								if ( start_column-1 >= 1 ){
									g[(start_column-2)*row+(start_row-1)] += 1;
								}
								if (start_row-1 >= 1  &&  start_column-1 >= 1){
									g[(start_column-2)*row+(start_row-2)] -= 1;
								}
							}else if (start_row == end_row){
								g[(end_column-1)*row+end_row-1] -= 1;
								g[(start_column-1)*row+start_row-1] += 1;
								if (start_row-1 >= 1){
									g[(end_column-1)*row+(start_row-2)] += 1;
									g[(start_column-1)*row+(start_row-2)] -= 1;
								}						
							}else if (start_column == end_column){
								g[(end_column-1)*row+end_row-1] -= 1;
								g[(start_column-1)*row+start_row-1] += 1;

							}*/


							fwrite(g,sizeof(int),row*column,outfile);
							fprintf(outfile2,"%d,5,%d,%d,%d,%d\n",num,ii,jj,ii+i-1,jj+j-1);
							num++;
						}
    /*------------------------------------------------------------------
	type 6
	------------------------------------------------------------------*/
      s=2;
	  t=2;
		for(i = t; i<=row; i=i+t)                                             
			for (j = s; j<=column; j=j+s)                   
				for ( ii = 1; ii<= row-i+1; ii++)       
					for (jj=1; jj<=column-j+1;jj++){
						memset(g, 0 , sizeof(g));  
						   for(k=ii;k<=ii+(i-1)/t;k++)
						       for (l=jj;l<=jj+(j-1)/s;l++)
									//g[(k-1)*column+l-1] = 1;
									g[(l-1)*row+k-1] = 1;
							for(k=ii; k<=ii+(i-1)/t;k++)
								for (l=jj+(j-1)/s+1;l<=jj+(j-1);l++)
									//g[(k-1)*column+l-1] = -1;
									g[(l-1)*row+k-1] = - 1;
							for(k=ii+(i-1)/t+1; k<=ii+(i-1);k++)
								for (l=jj;l<=jj+(j-1)/s;l++)
									//g[(k-1)*column+l-1] = -1;
									g[(l-1)*row+k-1] = -1;
							for(k=ii+(i-1)/t+1; k<=ii+(i-1);k++)
								for (l=jj+(j-1)/s+1;l<=(jj+j-1);l++)
									//g[(k-1)*column+l-1] = 1;
									g[(l-1)*row+k-1] = -1;


						/*start_row = ii;                                               
		                start_column = jj;                                            
		                end_row = ii+(i-1)/t;
						end_column = jj+(j-1)/s;                                      
						if (start_row != end_row && start_column != end_column){      
							g[(start_column-1)*row+start_row-1] += 1;             
							g[(end_column-1)*row+end_row-1] += 1;                 
							g[(start_column-1)*row+end_row-1] -= 1;               
							g[(end_column-1)*row+start_row-1] -= 1;               
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] += 1;                 
							if ( start_row-1 >= 1 ){                              
								g[(end_column-1)*row+(start_row-2)] -= 1;     
							}                                                     
							if ( start_column-1 >= 1 ){                           
								g[(start_column-2)*row+(start_row-1)] -= 1;   
							}                                                     
							if (start_row-1 >= 1  &&  start_column-1 >= 1){       
								g[(start_column-2)*row+(start_row-2)] += 1;   
							}                                                     
						}else if (start_row == end_row){                              
							g[(end_column-1)*row+end_row-1] += 1;                 
							g[(start_column-1)*row+start_row-1] -= 1;             
							if (start_row-1 >= 1){                                
								g[(end_column-1)*row+(start_row-2)] -= 1;     
								g[(start_column-1)*row+(start_row-2)] += 1;   
							}						      
						}else if (start_column == end_column){                        
							g[(end_column-1)*row+end_row-1] += 1;                 
							g[(start_column-1)*row+start_row-1] -= 1;             
						                                                              
						}                                                             
						start_row = ii;                                               
						start_column = jj+(j-1)/s+1;                                  
						end_row = ii+(i-1)/t;                                         
						end_column = jj+(j-1);                                        
						if (start_row != end_row && start_column != end_column){      
							g[(start_column-1)*row+start_row-1] -= 1;             
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+end_row-1] += 1;               
							g[(end_column-1)*row+start_row-1] += 1;               
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] -= 1;                 
							if ( start_row-1 >= 1 ){                              
								g[(end_column-1)*row+(start_row-2)] += 1;     
							}                                                     
							if ( start_column-1 >= 1 ){                           
								g[(start_column-2)*row+(start_row-1)] += 1;   
							}                                                     
							if (start_row-1 >= 1  &&  start_column-1 >= 1){       
								g[(start_column-2)*row+(start_row-2)] -= 1;   
							}                                                     
						}else if (start_row == end_row){                              
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
							if (start_row-1 >= 1){                                
								g[(end_column-1)*row+(start_row-2)] += 1;     
								g[(start_column-1)*row+(start_row-2)] -= 1;   
							}						      
						}else if (start_column == end_column){                        
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
						                                                              
						}                                                             
						start_row = ii+(i-1)/t+1;                                     
						start_column = jj+(j-1)/s+1;                                  
						end_row = ii+(i-1);                                           
						end_column = jj+(j-1);                                        
						if (start_row != end_row && start_column != end_column){      
							g[(start_column-1)*row+start_row-1] -= 1;             
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+end_row-1] += 1;               
							g[(end_column-1)*row+start_row-1] += 1;               
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] -= 1;                 
							if ( start_row-1 >= 1 ){                              
								g[(end_column-1)*row+(start_row-2)] += 1;     
							}                                                     
							if ( start_column-1 >= 1 ){                           
								g[(start_column-2)*row+(start_row-1)] += 1;   
							}                                                     
							if (start_row-1 >= 1  &&  start_column-1 >= 1){       
								g[(start_column-2)*row+(start_row-2)] -= 1;   
							}                                                     
						}else if (start_row == end_row){                              
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
							if (start_row-1 >= 1){                                
								g[(end_column-1)*row+(start_row-2)] += 1;     
								g[(start_column-1)*row+(start_row-2)] -= 1;   
							}						      
						}else if (start_column == end_column){                        
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
						                                                              
						}                                                           
						start_row = ii+(i-1)/t+1;                                     
						start_column = jj;                                            
						end_row = ii+(i-1);                                           
						end_column = jj+(j-1)/s;                                      
						if (start_row != end_row && start_column != end_column){      
							g[(start_column-1)*row+start_row-1] -= 1;             
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+end_row-1] += 1;               
							g[(end_column-1)*row+start_row-1] += 1;               
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] -= 1;                 
							if ( start_row-1 >= 1 ){                              
								g[(end_column-1)*row+(start_row-2)] += 1;     
							}                                                     
							if ( start_column-1 >= 1 ){                           
								g[(start_column-2)*row+(start_row-1)] += 1;   
							}                                                     
							if (start_row-1 >= 1  &&  start_column-1 >= 1){       
								g[(start_column-2)*row+(start_row-2)] -= 1;   
							}                                                     
						}else if (start_row == end_row){                              
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
							if (start_row-1 >= 1){                                
								g[(end_column-1)*row+(start_row-2)] += 1;     
								g[(start_column-1)*row+(start_row-2)] -= 1;   
							}						      
						}else if (start_column == end_column){                        
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
						                                                              
						}                           */                                  


							fwrite(g,sizeof(int),row*column,outfile);
							fprintf(outfile2,"%d,6,%d,%d,%d,%d\n",num,ii,jj,ii+i-1,jj+j-1);
							num++;
			}//end for (i,j)
			

	/*------------------------------------------------------------------
	type 7
	------------------------------------------------------------------*/
      s=2;
	  t=2;
		for(i = t; i<=row; i=i+t)                                             
			for (j = s; j<=column; j=j+s)                   
				for ( ii = 1; ii<= row-i+1; ii++)       
					for (jj=1; jj<=column-j+1;jj++){
						memset(g, 0 , sizeof(g));  

						   for(k=ii;k<=ii+(i-1)/t;k++)
						       for (l=jj;l<=jj+(j-1)/s;l++)
									//g[(k-1)*column+l-1] = 1;
									g[(l-1)*row+k-1] = -1;
							for(k=ii; k<=ii+(i-1)/t;k++)
								for (l=jj+(j-1)/s+1;l<=jj+(j-1);l++)
									//g[(k-1)*column+l-1] = -1;
									g[(l-1)*row+k-1] = 1;
							for(k=ii+(i-1)/t+1; k<=ii+(i-1);k++)
								for (l=jj;l<=jj+(j-1)/s;l++)
									//g[(k-1)*column+l-1] = -1;
									g[(l-1)*row+k-1] = -1;
							for(k=ii+(i-1)/t+1; k<=ii+(i-1);k++)
								for (l=jj+(j-1)/s+1;l<=(jj+j-1);l++)
									//g[(k-1)*column+l-1] = 1;
									g[(l-1)*row+k-1] = -1;

						/*start_row = ii;                                               
		                start_column = jj;                                            
		                end_row = ii+(i-1)/t;
						end_column = jj+(j-1)/s;                                      
						if (start_row != end_row && start_column != end_column){      
							g[(start_column-1)*row+start_row-1] -= 1;             
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+end_row-1] += 1;               
							g[(end_column-1)*row+start_row-1] += 1;               
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] -= 1;                 
							if ( start_row-1 >= 1 ){                              
								g[(end_column-1)*row+(start_row-2)] += 1;     
							}                                                     
							if ( start_column-1 >= 1 ){                           
								g[(start_column-2)*row+(start_row-1)] += 1;   
							}                                                     
							if (start_row-1 >= 1  &&  start_column-1 >= 1){       
								g[(start_column-2)*row+(start_row-2)] -= 1;   
							}                                                     
						}else if (start_row == end_row){                              
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
							if (start_row-1 >= 1){                                
								g[(end_column-1)*row+(start_row-2)] += 1;     
								g[(start_column-1)*row+(start_row-2)] -= 1;   
							}						      
						}else if (start_column == end_column){                        
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
						                                                              
						}                                                              
						start_row = ii;                                               
						start_column = jj+(j-1)/s+1;                                  
						end_row = ii+(i-1)/t;                                         
						end_column = jj+(j-1);                                        
						if (start_row != end_row && start_column != end_column){      
							g[(start_column-1)*row+start_row-1] += 1;             
							g[(end_column-1)*row+end_row-1] += 1;                 
							g[(start_column-1)*row+end_row-1] -= 1;               
							g[(end_column-1)*row+start_row-1] -= 1;               
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] += 1;                 
							if ( start_row-1 >= 1 ){                              
								g[(end_column-1)*row+(start_row-2)] -= 1;     
							}                                                     
							if ( start_column-1 >= 1 ){                           
								g[(start_column-2)*row+(start_row-1)] -= 1;   
							}                                                     
							if (start_row-1 >= 1  &&  start_column-1 >= 1){       
								g[(start_column-2)*row+(start_row-2)] += 1;   
							}                                                     
						}else if (start_row == end_row){                              
							g[(end_column-1)*row+end_row-1] += 1;                 
							g[(start_column-1)*row+start_row-1] -= 1;             
							if (start_row-1 >= 1){                                
								g[(end_column-1)*row+(start_row-2)] -= 1;     
								g[(start_column-1)*row+(start_row-2)] += 1;   
							}						      
						}else if (start_column == end_column){                        
							g[(end_column-1)*row+end_row-1] += 1;                 
							g[(start_column-1)*row+start_row-1] -= 1;             
						                                                              
						}                                                                                          
						start_row = ii+(i-1)/t+1;                                     
						start_column = jj+(j-1)/s+1;                                  
						end_row = ii+(i-1);                                           
						end_column = jj+(j-1);                                        
						if (start_row != end_row && start_column != end_column){      
							g[(start_column-1)*row+start_row-1] -= 1;             
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+end_row-1] += 1;               
							g[(end_column-1)*row+start_row-1] += 1;               
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] -= 1;                 
							if ( start_row-1 >= 1 ){                              
								g[(end_column-1)*row+(start_row-2)] += 1;     
							}                                                     
							if ( start_column-1 >= 1 ){                           
								g[(start_column-2)*row+(start_row-1)] += 1;   
							}                                                     
							if (start_row-1 >= 1  &&  start_column-1 >= 1){       
								g[(start_column-2)*row+(start_row-2)] -= 1;   
							}                                                     
						}else if (start_row == end_row){                              
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
							if (start_row-1 >= 1){                                
								g[(end_column-1)*row+(start_row-2)] += 1;     
								g[(start_column-1)*row+(start_row-2)] -= 1;   
							}						      
						}else if (start_column == end_column){                        
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
						                                                              
						}                                                           
						start_row = ii+(i-1)/t+1;                                     
						start_column = jj;                                            
						end_row = ii+(i-1);                                           
						end_column = jj+(j-1)/s;                                      
						if (start_row != end_row && start_column != end_column){      
							g[(start_column-1)*row+start_row-1] -= 1;             
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+end_row-1] += 1;               
							g[(end_column-1)*row+start_row-1] += 1;               
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] -= 1;                 
							if ( start_row-1 >= 1 ){                              
								g[(end_column-1)*row+(start_row-2)] += 1;     
							}                                                     
							if ( start_column-1 >= 1 ){                           
								g[(start_column-2)*row+(start_row-1)] += 1;   
							}                                                     
							if (start_row-1 >= 1  &&  start_column-1 >= 1){       
								g[(start_column-2)*row+(start_row-2)] -= 1;   
							}                                                     
						}else if (start_row == end_row){                              
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
							if (start_row-1 >= 1){                                
								g[(end_column-1)*row+(start_row-2)] += 1;     
								g[(start_column-1)*row+(start_row-2)] -= 1;   
							}						      
						}else if (start_column == end_column){                        
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
						                                                              
						}                                                             */


							fwrite(g,sizeof(int),row*column,outfile);
							fprintf(outfile2,"%d,7,%d,%d,%d,%d\n",num,ii,jj,ii+i-1,jj+j-1);
							num++;
						
			}//end for (i,j)
    /*------------------------------------------------------------------
	type 8
	------------------------------------------------------------------*/
      s=2;
	  t=2;
		for(i = t; i<=row; i=i+t)                                             
			for (j = s; j<=column; j=j+s)                   
				for ( ii = 1; ii<= row-i+1; ii++)       
					for (jj=1; jj<=column-j+1;jj++){
						memset(g, 0 , sizeof(g));  

							for(k=ii;k<=ii+(i-1)/t;k++)
						       for (l=jj;l<=jj+(j-1)/s;l++)
									//g[(k-1)*column+l-1] = 1;
									g[(l-1)*row+k-1] = -1;
							for(k=ii; k<=ii+(i-1)/t;k++)
								for (l=jj+(j-1)/s+1;l<=jj+(j-1);l++)
									//g[(k-1)*column+l-1] = -1;
									g[(l-1)*row+k-1] = -1;
							for(k=ii+(i-1)/t+1; k<=ii+(i-1);k++)
								for (l=jj;l<=jj+(j-1)/s;l++)
									//g[(k-1)*column+l-1] = -1;
									g[(l-1)*row+k-1] = -1;
							for(k=ii+(i-1)/t+1; k<=ii+(i-1);k++)
								for (l=jj+(j-1)/s+1;l<=(jj+j-1);l++)
									//g[(k-1)*column+l-1] = 1;
									g[(l-1)*row+k-1] = +1;

						/*start_row = ii;                                               
		                start_column = jj;                                            
		                end_row = ii+(i-1)/t;
						end_column = jj+(j-1)/s;                                      
						if (start_row != end_row && start_column != end_column){      
							g[(start_column-1)*row+start_row-1] -= 1;             
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+end_row-1] += 1;               
							g[(end_column-1)*row+start_row-1] += 1;               
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] -= 1;                 
							if ( start_row-1 >= 1 ){                              
								g[(end_column-1)*row+(start_row-2)] += 1;     
							}                                                     
							if ( start_column-1 >= 1 ){                           
								g[(start_column-2)*row+(start_row-1)] += 1;   
							}                                                     
							if (start_row-1 >= 1  &&  start_column-1 >= 1){       
								g[(start_column-2)*row+(start_row-2)] -= 1;   
							}                                                     
						}else if (start_row == end_row){                              
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
							if (start_row-1 >= 1){                                
								g[(end_column-1)*row+(start_row-2)] += 1;     
								g[(start_column-1)*row+(start_row-2)] -= 1;   
							}						      
						}else if (start_column == end_column){                        
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
						                                                              
						}                                                              
						start_row = ii;                                               
						start_column = jj+(j-1)/s+1;                                  
						end_row = ii+(i-1)/t;                                         
						end_column = jj+(j-1);                                        
						if (start_row != end_row && start_column != end_column){      
							g[(start_column-1)*row+start_row-1] -= 1;             
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+end_row-1] += 1;               
							g[(end_column-1)*row+start_row-1] += 1;               
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] -= 1;                 
							if ( start_row-1 >= 1 ){                              
								g[(end_column-1)*row+(start_row-2)] += 1;     
							}                                                     
							if ( start_column-1 >= 1 ){                           
								g[(start_column-2)*row+(start_row-1)] += 1;   
							}                                                     
							if (start_row-1 >= 1  &&  start_column-1 >= 1){       
								g[(start_column-2)*row+(start_row-2)] -= 1;   
							}                                                     
						}else if (start_row == end_row){                              
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
							if (start_row-1 >= 1){                                
								g[(end_column-1)*row+(start_row-2)] += 1;     
								g[(start_column-1)*row+(start_row-2)] -= 1;   
							}						      
						}else if (start_column == end_column){                        
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
						                                                              
						}                                                           
						start_row = ii+(i-1)/t+1;                                     
						start_column = jj+(j-1)/s+1;                                  
						end_row = ii+(i-1);                                           
						end_column = jj+(j-1);                                        
						if (start_row != end_row && start_column != end_column){      
							g[(start_column-1)*row+start_row-1] -= 1;             
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+end_row-1] += 1;               
							g[(end_column-1)*row+start_row-1] += 1;               
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] -= 1;                 
							if ( start_row-1 >= 1 ){                              
								g[(end_column-1)*row+(start_row-2)] += 1;     
							}                                                     
							if ( start_column-1 >= 1 ){                           
								g[(start_column-2)*row+(start_row-1)] += 1;   
							}                                                     
							if (start_row-1 >= 1  &&  start_column-1 >= 1){       
								g[(start_column-2)*row+(start_row-2)] -= 1;   
							}                                                     
						}else if (start_row == end_row){                              
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
							if (start_row-1 >= 1){                                
								g[(end_column-1)*row+(start_row-2)] += 1;     
								g[(start_column-1)*row+(start_row-2)] -= 1;   
							}						      
						}else if (start_column == end_column){                        
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
						                                                              
						}                                                           
						start_row = ii+(i-1)/t+1;                                     
						start_column = jj;                                            
						end_row = ii+(i-1);                                           
						end_column = jj+(j-1)/s;                                      
						if (start_row != end_row && start_column != end_column){      
							g[(start_column-1)*row+start_row-1] += 1;             
							g[(end_column-1)*row+end_row-1] += 1;                 
							g[(start_column-1)*row+end_row-1] -= 1;               
							g[(end_column-1)*row+start_row-1] -= 1;               
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] += 1;                 
							if ( start_row-1 >= 1 ){                              
								g[(end_column-1)*row+(start_row-2)] -= 1;     
							}                                                     
							if ( start_column-1 >= 1 ){                           
								g[(start_column-2)*row+(start_row-1)] -= 1;   
							}                                                     
							if (start_row-1 >= 1  &&  start_column-1 >= 1){       
								g[(start_column-2)*row+(start_row-2)] += 1;   
							}                                                     
						}else if (start_row == end_row){                              
							g[(end_column-1)*row+end_row-1] += 1;                 
							g[(start_column-1)*row+start_row-1] -= 1;             
							if (start_row-1 >= 1){                                
								g[(end_column-1)*row+(start_row-2)] -= 1;     
								g[(start_column-1)*row+(start_row-2)] += 1;   
							}						      
						}else if (start_column == end_column){                        
							g[(end_column-1)*row+end_row-1] += 1;                 
							g[(start_column-1)*row+start_row-1] -= 1;             
						                                                              
						}                                                                    */

							fwrite(g,sizeof(int),row*column,outfile);
							fprintf(outfile2,"%d,8,%d,%d,%d,%d\n",num,ii,jj,ii+i-1,jj+j-1);
							num++;
						
			}//end for (i,j)

    /*------------------------------------------------------------------
	type 9
	------------------------------------------------------------------*/
      s=2;
	  t=2;
		for(i = t; i<=row; i=i+t)                                             
			for (j = s; j<=column; j=j+s)                   
				for ( ii = 1; ii<= row-i+1; ii++)       
					for (jj=1; jj<=column-j+1;jj++){
						memset(g, 0 , sizeof(g));  
							for(k=ii;k<=ii+(i-1)/t;k++)
						       for (l=jj;l<=jj+(j-1)/s;l++)
									//g[(k-1)*column+l-1] = 1;
									g[(l-1)*row+k-1] = -1;
							for(k=ii; k<=ii+(i-1)/t;k++)
								for (l=jj+(j-1)/s+1;l<=jj+(j-1);l++)
									//g[(k-1)*column+l-1] = -1;
									g[(l-1)*row+k-1] = -1;
							for(k=ii+(i-1)/t+1; k<=ii+(i-1);k++)
								for (l=jj;l<=jj+(j-1)/s;l++)
									//g[(k-1)*column+l-1] = -1;
									g[(l-1)*row+k-1] = 1;
							for(k=ii+(i-1)/t+1; k<=ii+(i-1);k++)
								for (l=jj+(j-1)/s+1;l<=(jj+j-1);l++)
									//g[(k-1)*column+l-1] = 1;
									g[(l-1)*row+k-1] = -1;

						/*start_row = ii;                                               
		                start_column = jj;                                            
		                end_row = ii+(i-1)/t;
						end_column = jj+(j-1)/s;                                      
						if (start_row != end_row && start_column != end_column){      
							g[(start_column-1)*row+start_row-1] -= 1;             
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+end_row-1] += 1;               
							g[(end_column-1)*row+start_row-1] += 1;               
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] -= 1;                 
							if ( start_row-1 >= 1 ){                              
								g[(end_column-1)*row+(start_row-2)] += 1;     
							}                                                     
							if ( start_column-1 >= 1 ){                           
								g[(start_column-2)*row+(start_row-1)] += 1;   
							}                                                     
							if (start_row-1 >= 1  &&  start_column-1 >= 1){       
								g[(start_column-2)*row+(start_row-2)] -= 1;   
							}                                                     
						}else if (start_row == end_row){                              
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
							if (start_row-1 >= 1){                                
								g[(end_column-1)*row+(start_row-2)] += 1;     
								g[(start_column-1)*row+(start_row-2)] -= 1;   
							}						      
						}else if (start_column == end_column){                        
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
						                                                              
						}                                                              
						start_row = ii;                                               
						start_column = jj+(j-1)/s+1;                                  
						end_row = ii+(i-1)/t;                                         
						end_column = jj+(j-1);                                        
						if (start_row != end_row && start_column != end_column){      
							g[(start_column-1)*row+start_row-1] -= 1;             
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+end_row-1] += 1;               
							g[(end_column-1)*row+start_row-1] += 1;               
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] -= 1;                 
							if ( start_row-1 >= 1 ){                              
								g[(end_column-1)*row+(start_row-2)] += 1;     
							}                                                     
							if ( start_column-1 >= 1 ){                           
								g[(start_column-2)*row+(start_row-1)] += 1;   
							}                                                     
							if (start_row-1 >= 1  &&  start_column-1 >= 1){       
								g[(start_column-2)*row+(start_row-2)] -= 1;   
							}                                                     
						}else if (start_row == end_row){                              
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
							if (start_row-1 >= 1){                                
								g[(end_column-1)*row+(start_row-2)] += 1;     
								g[(start_column-1)*row+(start_row-2)] -= 1;   
							}						      
						}else if (start_column == end_column){                        
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
						                                                              
						}                                                           
						start_row = ii+(i-1)/t+1;                                     
						start_column = jj+(j-1)/s+1;                                  
						end_row = ii+(i-1);                                           
						end_column = jj+(j-1);                                        
						if (start_row != end_row && start_column != end_column){      
							g[(start_column-1)*row+start_row-1] += 1;             
							g[(end_column-1)*row+end_row-1] += 1;                 
							g[(start_column-1)*row+end_row-1] -= 1;               
							g[(end_column-1)*row+start_row-1] -= 1;               
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] += 1;                 
							if ( start_row-1 >= 1 ){                              
								g[(end_column-1)*row+(start_row-2)] -= 1;     
							}                                                     
							if ( start_column-1 >= 1 ){                           
								g[(start_column-2)*row+(start_row-1)] -= 1;   
							}                                                     
							if (start_row-1 >= 1  &&  start_column-1 >= 1){       
								g[(start_column-2)*row+(start_row-2)] += 1;   
							}                                                     
						}else if (start_row == end_row){                              
							g[(end_column-1)*row+end_row-1] += 1;                 
							g[(start_column-1)*row+start_row-1] -= 1;             
							if (start_row-1 >= 1){                                
								g[(end_column-1)*row+(start_row-2)] -= 1;     
								g[(start_column-1)*row+(start_row-2)] += 1;   
							}						      
						}else if (start_column == end_column){                        
							g[(end_column-1)*row+end_row-1] += 1;                 
							g[(start_column-1)*row+start_row-1] -= 1;             
						                                                              
						}                                                                                             
						start_row = ii+(i-1)/t+1;                                     
						start_column = jj;                                            
						end_row = ii+(i-1);                                           
						end_column = jj+(j-1)/s;                                      
				        if (start_row != end_row && start_column != end_column){      
							g[(start_column-1)*row+start_row-1] -= 1;             
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+end_row-1] += 1;               
							g[(end_column-1)*row+start_row-1] += 1;               
						}else if (start_row == end_row && start_column == end_column){
							g[(end_column-1)*row+end_row-1] -= 1;                 
							if ( start_row-1 >= 1 ){                              
								g[(end_column-1)*row+(start_row-2)] += 1;     
							}                                                     
							if ( start_column-1 >= 1 ){                           
								g[(start_column-2)*row+(start_row-1)] += 1;   
							}                                                     
							if (start_row-1 >= 1  &&  start_column-1 >= 1){       
								g[(start_column-2)*row+(start_row-2)] -= 1;   
							}                                                     
						}else if (start_row == end_row){                              
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
							if (start_row-1 >= 1){                                
								g[(end_column-1)*row+(start_row-2)] += 1;     
								g[(start_column-1)*row+(start_row-2)] -= 1;   
							}						      
						}else if (start_column == end_column){                        
							g[(end_column-1)*row+end_row-1] -= 1;                 
							g[(start_column-1)*row+start_row-1] += 1;             
						                                                              
						}                                                                        */

							fwrite(g,sizeof(int),row*column,outfile);
							fprintf(outfile2,"%d,9,%d,%d,%d,%d\n",num,ii,jj,ii+i-1,jj+j-1);
							num++;
						
			}//end for (i,j)


	time ( &End );

	TimeUsed = difftime( End, Start ); 
	printf("total number is %d\n", num);
	printf("total time is %8.11f seconds\n", TimeUsed);

}// end main

